<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--引入easyui的样式 -->
<link rel="stylesheet"  type="text/css" href="../themes/default/easyui.css">
<link rel="stylesheet"  type="text/css" href="../themes/icon.css">
<!-- js文件 -->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../js/easyui-lang-zh_CN.js"></script>
<title>Insert title here</title>
</head>
<script type="text/javascript">
/* page页面显示  分页 */
$(function(){
	//更改底部工具栏
	var pager = $('#HostelList').datagrid('getPager');	
	  pager.pagination({
		pageList: [10,20,30],
	});
})
/* 增加住户 */

	$(function() {
		/* 弹出添加窗口  */
		$("#appendStu").click(function() {
			var rows = $('#HostelList').datagrid('getSelections');
			if (rows.length != 0 && rows[0].count<rows[0].hnumber) {
				$("#aaa").datagrid({
					data:[
					      {"text":(rows[0].hid+"-"+rows[0].hbuiding),"group":"寝室名"},
					      {"text":(rows[0].count+" /"+rows[0].hnumber),"group":"住户数 /最大住户数"},
					      {"text":(rows[0].hname),"group":"住户姓名"}
					      ]
				})
				$("#dlg").dialog("open");
			} else {
				$.messager.show({
					title : '提示',
					msg : '请选择未住满的宿舍',
					timeout : 1000,
					showType : 'slide',
					style : {
						right : ''
					}
				});
			}
		})
		/* 点击取消 */
		$("#closeAppendStu").click(function() {
			$('#ff').form('clear');
			$("#dlg").dialog("close");
		})
		/* 点击提交 */
		$("#saveAppendStu").click(function() {
			var rows = $('#HostelList').datagrid('getSelections');
			var hid = rows[0].hid;
			$('#ff').form({
				url : "getHostelUpdate",
				onSubmit : function(param) {
					param.hid = hid;
					return $(this).form('enableValidation').form('validate');
				},
				success : function(data) {
					if (data) {
						location.reload();
					} else {
						alert("添加失败请查看姓名学号是否输入正确");
					}
				}
			});
			// submit the form    
			$('#ff').submit();
		})
	})
	/* 取消操作 */
	$(function() {
		$("#reject").click(function() {
			$("#HostelList").datagrid('uncheckAll');
			$("#HostelList").datagrid('rejectChanges');
		})
	})
</script>
<body>
		<!--                           展示寝室信息                                                                     -->
	 <table id="HostelList" title="学生信息查询" class="easyui-datagrid"
            toolbar="#toolbar" pagination="true" fit="true" 
            data-options="url:'getHostelSelect',method:'post',singleSelect:true" striped="true"
            rownumbers="true" fitColumns="true" border="false">
        <thead>
            <tr>
                <th field="ck" checkbox=true></th>
                <th field="hid" width='30' resizable='false' data-options="editor:'numberbox'">寝室名</th>
                <th field="hname" width='80' resizable='false' data-options="editor:'text'">住户</th>
                <th field="hbuiding" width='50' resizable='false' data-options="editor:'text'">宿舍楼</th>
                <th field="count" width='50' resizable='false'>住户人数</th>
                <th field="hnumber" width='50' resizable='false' data-options="editor:'numberbox'">最大住户人数</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a id="appendStu" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
        <a id="reject" class="easyui-linkbutton" iconCls="icon-undo" plain="true">取消</a>
    </div>
    
    <!-- 添加住户信息 -->
     <div id="dlg" class="easyui-dialog" title="学生宿舍添加系统" style="width:400px;height:450px;padding:10px"
			data-options="
				closed: 'true',
				iconCls: 'icon-save',
				buttons: '#dlg-buttons',
				maximizable: 'true',
				modal:'true',
			">
			<!-- 被选中寝室信息展示  -->
			<div id="aaa" class="easyui-datalist" title="寝室信息" style="width:100%;height:55%;border:none" data-options="
			groupField: 'group'
			">
		</div>
		<div class="easyui-panel" style="width: 100%; height: 45%; border: none">
			<div style="padding: 10px 30px 20px 0px">
				<form id="ff" method="post">
					<table cellpadding="5">
						<tr>
							<td>添加住户学号:</td>
							<td><input class="easyui-textbox" type="text" name="sid"
								data-options="required:true"></input></td>
						</tr>
						<tr>
							<td>添加住户姓名:</td>
							<td><input class="easyui-textbox" type="text" name="sname"
								data-options="required:true"></input></td>
						</tr>
					</table>
				</form>
			</div>
			</div>
		</div>
	</div>
	<div id="dlg-buttons">
		<a id="saveAppendStu" href="#" class="easyui-linkbutton">添加</a>
		<a id="closeAppendStu" href="#" class="easyui-linkbutton">取消</a>
	</div>
</body>
</body>
</html>